package org.lanqiao.tjut.controller;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.EmployeeBean;
import org.lanqiao.tjut.model.ModelFactory;
import org.lanqiao.tjut.myUtils.MyUtils;

/**
 * Servlet implementation class EmployeeInfoServlet
 */
@WebServlet("/EmployeeInfoServlet")
@MultipartConfig(maxFileSize=5000000)
public class EmployeeInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		//使用实体类进行传参 
//		EmployeeBean empB = MyUtils.getNewInstance(EmployeeBean.class);
//		//将前台的页面传入值 赋值给实体变量
//		
//		empB.setEmp_name(request.getParameter("txtName"));
//		empB.setEmp_sex(request.getParameter("txtSex"));
//		empB.setEmp_date(MyUtils.convertString2Date(request.getParameter("txtDate"), "yyyy-MM-dd"));
//		empB.setEmp_age(request.getParameter("txtAge"));
//		empB.setEmp_tel(request.getParameter("txtNum" ));
//		empB.setEmp_ad(request.getParameter("txtAD"));
//		empB.setEmp_img(request.getParameter(""));
//	
		// 调用换行方法，将request对象中的参数依次赋值给实体类
		EmployeeBean empB = MyUtils.convertRequest2Bean(request, EmployeeBean.class, "uploadfies/stuImgs/",
						"stImg");
				// 输出打印前台表单数据
				System.out.println("stu::" + empB.toString());

				// 调用model层进行数据库保存
				int i = ModelFactory.getEmployeeInfoAddModelInstance().addEmployeeInfo(empB);
				// 保存之后的跳转处理
				if (i > 0) {
					// 保存成功
					request.getRequestDispatcher("WEB-INF/logined/employeeInfoManager/employeeAdded.jsp").forward(request,
							response);
				} else {
					// 保存失败
					response.getWriter().write(
							"<script language='javascript'>alert('数据保存或更新失败!');"
							+ "location.href='DispatchCommServlet?"
							+ "jp=WEB-INF/logined/employeeInfoManager/employeeInfoAdd';</script>");
      
	    }

		
	}

}
